﻿using Microsoft.AspNetCore.Mvc.ModelBinding;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace a001.Models
{
    public class Aroots
    {
        public void CopyFile(string sourceFileName, string destinationFileName)
        {
            try
            {
                string folderName = System.IO.Path.GetFileName(sourceFileName);
                string destfolderdir = System.IO.Path.Combine(destinationFileName, folderName);
                string[] filenames = System.IO.Directory.GetFileSystemEntries(sourceFileName);
                foreach (string file in filenames)// 遍历所有的文件和目录
                {
                    if (System.IO.Directory.Exists(file))
                    {
                        string currentdir = System.IO.Path.Combine(destfolderdir, System.IO.Path.GetFileName(file));
                        if (!System.IO.Directory.Exists(currentdir))
                        {
                            System.IO.Directory.CreateDirectory(currentdir);
                        }
                        CopyFile(file, destfolderdir);
                    }
                    else
                    {
                        string srcfileName = System.IO.Path.Combine(destfolderdir, System.IO.Path.GetFileName(file));
                        if (!System.IO.Directory.Exists(destfolderdir))
                        {
                            System.IO.Directory.CreateDirectory(destfolderdir);
                        }
                        System.IO.File.Copy(file, srcfileName);
                    }
                }

            }
            catch (Exception e)
            {

            }
        }
    }
}
